#include <cstdio>
#include <cstring>

int a[ 1001 ], b[ 1001 ];
char map[ 1001 ][ 1001 ];

int main( )
{
    int n, t, q, i, j, ans, x, y, cas = 1;
    scanf("%d", &t);
    while ( t-- )
    {
        scanf("%d", &n);
        for ( i = 0; i < n; i++ )
            scanf("%s", map[ i ]);
        memset( a, 0, sizeof( a ) );
        memset( b, 0, sizeof( b ) );
        scanf("%d", &q);
        while ( q-- )
        {
            scanf("%d%d", &x, &y); x--; y--;
            a[ x ]++;
            b[ y ]++;
        }
        ans = 0;
        for ( i = 0; i < n; i++ )
            for ( j = 0; j < n; j++ )
            {
                if ( map[ i ][ j ] == 'w' )
                    if ( ( a[ i ] + b[ j ] ) % 2 == 0 )
                        ans++;
                if ( map[ i ][ j ] == 'b' )
                    if ( ( a[ i ] + b[ j ] ) % 2 )
                        ans++;
            }
        printf("Case #%d: %d\n", cas++, ans);
    }
    return 0;
}
